<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>修改用户信息 </title>
		<%@ include file="/WEB-INF/jspf/taglibs.jspf"%>
		<%@ include file="/WEB-INF/jspf/statics.jspf"%>
</head>
<body>
<div id="wrapper">

    <div class="submit-form pusht">
        <form name="submit-form" id="submit-form" action="">
            <table class="form label-colored-form">
                <c:if test="${operationType=='add'}">
                    <tbody>
                    <tr class="sprite">
                        <td class="label-td"><label>用户编号：</label></td>
                        <td><input type="text" name="loginName" id="loginName" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>姓名：</label></td>
                        <td><input type="text" name="realName" id="realName" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>等级：</label></td>
                         <td>
                         	<select name="roleId" id="roleId">
                                <option value=1>等级一</option>
                                <option value=2>等级二</option>
                                <option value=2>等级三</option>
                            </select>
                         </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>身份证：</label></td>
                        <td><input type="text" name="identityCard" id="identityCard" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>电话：</label></td>
                        <td><input type="text" name="phoneNum" id="phoneNum" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>部门：</label></td>
                        <td>
                            <select name="departmentId" id="departmentId">
                                <option value="1">部门一</option>
                                <option value="2">部门二</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                        <!-- <input type="submit" value="添加" id="btnOK" class="btn btn-primary" id="btn_confirm"> -->
                            <button class="btn btn-primary" id="btn_confirm">添加</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if>
                
                
             <%--   <c:if test="${operationType !='add'}">
                    <input type="hidden" name="id" value="${venue.id}"/>
                  <tbody>
                    <tr class="sprite">
                        <td class="label-td"><label>用户编号：</label></td>
                        <td><input type="text" name="loginName" id="loginName" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>姓名：</label></td>
                        <td><input type="text" name="realName" id="realName" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>等级：</label></td>
                         <td>
                         	<select name="roleId" id="roleId">
                                <option value=1>等级一</option>
                                <option value=2>等级二</option>
                                <option value=2>等级三</option>
                            </select>
                         </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>身份证：</label></td>
                        <td><input type="text" name="identityCard" id="identityCard" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label>电话：</label></td>
                        <td><input type="text" name="phoneNum" id="phoneNum" value="" maxlength="20" style="width:200px;" class="text required"></td>
                    </tr>
                   <tr class="sprite">
                        <td class="label-td"><label>部门：</label></td>
                        <td>
                            <select name="departmentId" id="departmentId">
                                <option value="1">部门一</option>
                                <option value="2">部门二</option>
                            </select>
                        </td>
                    </tr>
                    <tr class="sprite">
                        <td class="label-td"><label></label></td>
                        <td>
                            <button class="btn btn-primary" id="btn_confirm1">保存</button>
                        </td>
                    </tr>
                    </tbody>
                </c:if> --%>
            </table>
        </form>
    </div>
</div>
</body>
</html>
<script type="text/javascript" src="${ctx }/js/jquery.form.js"></script>
<script type="text/javascript" src="${ctx }/js/jquery.validate.js"></script>
<script type="text/javascript">
var checkresult=true;
  $(document).ready(function () {
	  $.ajaxSetup ({
			cache: false //关闭AJAX相应的缓存
			}); // 关闭缓存功能
       jQuery.validator.addMethod("isIdCardNo", function(value, element) {       
    	     return this.optional(element) || isIdCardNo(value);       
    	   }, "请正确输入您的身份证号码");
       
    // 联系电话(手机/电话皆可)验证
       jQuery.validator.addMethod("isPhone", function(value,element) {
       var length = value.length;
       var mobile = /^(((13[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
       var tel = /^\d{3,4}-?\d{7,9}$/;
       return this.optional(element) || (tel.test(value) || mobile.test(value));
         
       }, "请正确填写您的联系电话");
    
        var result = $("#submit-form").validate({  
       	   rules: {  
       	      loginName: {  
       	         required: true,  
       	         minlength: 2  
       	      },
       	      identityCard:{
       	    	isIdCardNo:true
       	      },
       	      phoneNum:{
       	    	isPhone:true
       	      }
       	   },  
       	   messages: {  
       		   loginName: {  
       	         required: '请输入编号',  
       	         minlength: '请至少输入两个字符'  
       	      },
       	      realName:{
       	    	required: '请输入姓名',  
      	         minlength: '请至少输入两个字符'
       	      },
       	  	 identityCard:{
      	    	required: '请输入身份证号'  
      	      },
      	    phoneNum:{
      	    	required: '请输入联系电话'  
      	      }
       	   },
	       	submitHandler: function(form) { 
	       	 var form = $("#submit-form"); 
	           var options  = {    
	              url:'${ctx }/account/update_user',    
	              type:'post',    
	              success:function(json)    
	              {  
	              	if (json == "success") {
	                  	parent.document.getElementById('success').click();
	                  } else {
	                  	parent.document.getElementById('fail').click();
	                  }
	              }   
	          };    
	          form.ajaxSubmit(options); 
	          dialog_close();
	        }
       	}
        );
  });
  
//增加身份证验证
  function isIdCardNo(num) {
      var factorArr = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1);
      var parityBit = new Array("1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2");
      var varArray = new Array();
      var intValue;
      var lngProduct = 0;
      var intCheckDigit;
      var intStrLen = num.length;
      var idNumber = num;
      // initialize
      if ((intStrLen != 15) && (intStrLen != 18)) {
          return false;
      }
      // check and set value
      for (i = 0; i < intStrLen; i++) {
          varArray[i] = idNumber.charAt(i);
          if ((varArray[i] < '0' || varArray[i] > '9') && (i != 17)) {
              return false;
          } else if (i < 17) {
              varArray[i] = varArray[i] * factorArr[i];
          }
      }
      if (intStrLen == 18) {
          //check date
          var date8 = idNumber.substring(6, 14);
          if (isDate8(date8) == false) {
              return false;
          }
          // calculate the sum of the products
          for (i = 0; i < 17; i++) {
              lngProduct = lngProduct + varArray[i];
          }
          // calculate the check digit
          intCheckDigit = parityBit[lngProduct % 11];
          // check last digit
          if (varArray[17] != intCheckDigit) {
              return false;
          }
      }
      else {        //length is 15
          //check date
          var date6 = idNumber.substring(6, 12);
          if (isDate6(date6) == false) {
              return false;
          }
      }
      return true;
  }
  function isDate6(sDate) {
      if (!/^[0-9]{6}$/.test(sDate)) {
          return false;
      }
      var year, month, day;
      year = sDate.substring(0, 4);
      month = sDate.substring(4, 6);
      if (year < 1700 || year > 2500) return false
      if (month < 1 || month > 12) return false
      return true
  }

  function isDate8(sDate) {
      if (!/^[0-9]{8}$/.test(sDate)) {
          return false;
      }
      var year, month, day;
      year = sDate.substring(0, 4);
      month = sDate.substring(4, 6);
      day = sDate.substring(6, 8);
      var iaMonthDays = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
      if (year < 1700 || year > 2500) return false
      if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1] = 29;
      if (month < 1 || month > 12) return false
      if (day < 1 || day > iaMonthDays[month - 1]) return false
      return true
  }
  
</script>